<template>
  <!-- 检验确认 -->
  <el-dialog title="治疗确认" :visible="value" width="600px" custom-class="dialog-box" @close="onClose" @open="onOpen" :close-on-click-modal="false" :append-to-body="true">
    <ul class="project-ul">
      <li class="overflow-omit" v-for="(item,index) in dataArr" :key="item.id">
        <el-checkbox v-model="item.check">{{item.checkName}}</el-checkbox>
      </li>
    </ul>
    <span slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: ["value", "curItem"],
  data() {
    return {
      btnLoading: false,
      dataArr: []
    };
  },
  methods: {
    onSubmit() {
      let th = this;
      let arr = [];
      th.dataArr.forEach(d => {
        if (d.check) {
          arr.push(d.id);
        }
      });
      if (arr.length == 0) {
        th.$message.warning("请勾选检查项目");
        return;
      }
      let j = {
        ids: arr.join(",")
      };
      th.btnLoading = true;
      th.$api
        .confirmedCheckcureAssistIds(j)
        .then(res => {
          if (res.executed) {
            th.$message.success("操作成功");
            th.$emit("success", arr.length);
            th.onClose();
          } else {
            th.$message.error(res.message);
          }
          th.btnLoading = false;
        })
        .catch(() => {
          th.btnLoading = false;
        });
    },
    getData() {
      let th = this;
      let j = {
        cureId: th.curItem.cureId
      };
      th.$api.cureAdvicepreConfirmedCheckcureId(j).then(res => {
        if (res.executed) {
          res.data.forEach(d => {
            d.check = true;
          });
          th.dataArr = res.data;
        }
      });
    },
    onOpen() {
      let th = this;
      th.getData();
      th.$nextTick(function() {});
    },
    onClose() {
      let th = this;
      th.$emit("input", false);
    }
  }
};
</script>
<style lang="scss" scoped>
.project-ul {
  padding: 0;
  margin: 0;
  overflow: hidden;
  > li {
    list-style: none;
    float: left;
    padding: 10px 0;
    width: 50%;
  }
}
</style>

